<?php
$output = array();

if (!isset($_GET["id"])) {
    echo("No id specified");
    exit();
}
$id = $_GET["id"];

// import database connection variables and connectToMysql method
require_once __DIR__ . '/db_config.php';

$mysqli = connectToMysql();
$query = "SELECT job.id, job.name, job.description, job.salary, job.companyId, job.jobUrl, job.active, job.postedDate, location.latitude, location.longitude FROM Job job left join Location location on job.location = location.id where job.id = " . $id;

if ($result = $mysqli->query($query)) {
    /* fetch object array */
    $row = $result->fetch_array();
    $output = array_map('utf8_encode', $row);

    $result->close();
}

/* close connection */
$mysqli->close();

$finalResult = json_encode($output, JSON_NUMERIC_CHECK);
$finalResult = str_replace('"salary":""', '"salary":NULL', $finalResult);
$finalResult = str_replace('"active":""', '"active":NULL', $finalResult);
$finalResult = str_replace('"active":0', '"active":true', $finalResult);
$finalResult = str_replace('"active":1', '"active":false', $finalResult);
$finalResult = str_replace('"latitude":""', '"latitude":NULL', $finalResult);
$finalResult = str_replace('"longitude":""', '"longitude":NULL', $finalResult);
echo $finalResult;
?>